package com.corechina.apex_osswords.common;

import sun.misc.BASE64Encoder;

import java.io.FileInputStream;
import java.io.IOException;

public class ImageUtils {

    public static String takeImageToBASE64(String uploadFilePath, String path) {
        String imageBASE64 = null;
        if (path != null && !path.equals("")) {
            try {
                FileInputStream inputFile = new FileInputStream(uploadFilePath + "/" + path);
                byte[] buffer = new byte[inputFile.available()];
                inputFile.read(buffer);
                inputFile.close();
                imageBASE64 = new BASE64Encoder().encode(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return imageBASE64;
    }

}
